package com.cy.cy2025.activity

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.cy.cy2025.databinding.ActivityRetrofitBinding
import com.cy.test250502.net.JsonTestApiService
import com.cy.test250502.net.TestInfoApiService
import kotlinx.coroutines.launch

class RetrofitActivity : AppCompatActivity() {

    val binding by lazy {
        ActivityRetrofitBinding.inflate(layoutInflater)
    }

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)


        binding.btn1.setOnClickListener {
            lifecycleScope.launch {
                val str = TestInfoApiService.testInfo()
                binding.tv1.text = str
            }
        }

        binding.btn2.setOnClickListener {
            lifecycleScope.launch {
                val info = JsonTestApiService.getTestJsonInfo()
                binding.tv2.text = "json内容:\nid = ${info?.id}, \nuserId = ${info?.userId}, \ntitle = ${info?.title}, \nbody = ${info?.body}"
            }
        }


    }
}


